/*
 * Description: autocad accelerator
 */
#include "acad_accelerator.h"
#include "Windows.h"
#include "log.h"
#include "performance/utils/perf_utils.h"
#include "performance/utils/registry_utils_ex.h"
#include "performance/perf_constants.h"
namespace PERF {

const std::string ACAD_DEFAULT_PROFILE_KEY =
    "\\Software\\Autodesk\\AutoCAD\\R24.3\\ACAD-7101:804\\Profiles\\<<\u672a\u547d\u540d\u914d\u7f6e>>\\General";
const std::string ACAD_STARTUP_ITEM_NAME = "UseStartUpDialog";
constexpr const DWORD ACAD_STARTUP_VALUE = 2;

bool AcadAccelerator::OnBegin(std::shared_ptr<PerfInfo> perfInfo)
{
    if (perfInfo == nullptr) {
        LOG_ERR("[PERF - OnBegin] - perfInfo is null!");
        return false;
    }
    if (perfInfo->appName != PNAME_AUTOCAD) {
        return true;
    }
    std::string subKey = PERF_UTILS.GetCurrentUserSid() + ACAD_DEFAULT_PROFILE_KEY;
    RegistryUtilsEx regModifier(HKEY_USERS, subKey);
    LONG ret = regModifier.RegSetDword(ACAD_STARTUP_ITEM_NAME, ACAD_STARTUP_VALUE);
    LOG_INFO("[PERF - OnBegin] - acad aclr {}", ret == ERROR_SUCCESS ? "succeed" : "failed");
    return ret == ERROR_SUCCESS;
}

bool AcadAccelerator::OnEnd(std::shared_ptr<PerfInfo> perfInfo)
{
    return true;
}

}  // namespace PERF